(function () {
    "use strict";

    angular.module('core').factory('pedidoCompraService', factory);
    factory.$inject = ['$http', '$q'];

    function factory($http, $q) {

        return {

            getByPedidoCompra: function (args) {
                var deferred = $q.defer();
                $http.post('/pedidoCompra/getbypedidoCompra', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            saveNewCompras: function (notaFiscal, itensCompras) {
                var deferred = $q.defer();
                var args = {
                    notaFiscal: notaFiscal,
                    itensCompras: itensCompras
                };
                $http.post('/pedidoCompra/savenewcompras', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            get: function (id) {
                var deferred = $q.defer();
                $http.post('/pedidoCompra/get', id)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            getAll: function (args) {
                var deferred = $q.defer();
                $http.post('/pedidoCompra/getall', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            count: function (args) {
                var deferred = $q.defer();
                $http.post('/pedidoCompra/count', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },

            prepareNew: function () {
                var deferred = $q.defer();
                $http.post('/pedidoCompra/prepareNew')
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            prepareNewItem: function (args) {
                var deferred = $q.defer();
                $http.post('/pedidoCompra/PrepareNewItem',args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            prepare: function (args) {
                var deferred = $q.defer();
                $http.post('/pedidoCompra/Prepare', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },

            save: function (item) {
                var deferred = $q.defer();
                $http.post('/pedidoCompra/save', item)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            delete: function (id) {
                var deferred = $q.defer();
                $http.post('/pedidoCompra/delete', id)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
        };
    }

})();


